package leetcode;

import java.util.Scanner;

//2020蓝桥杯回文日期(一些年月日的细节容易出错，找出回文的特点从对称入手)
public class Palindrome_date {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int num=n/10000;
        int x,l;
        while (true){
           x=(num*10000)+date(num);
            if(x>(num*10000)&&x!=n)break;
            num++;
        }
        num=n/10000;
        while(true){
            int m,d,m_1,m_2,d_1,d_2;
            m_1=num%10;
            m_2=(num/10)%10;
            m=m_1*10+m_2;
            d_1=(num/100)%10;
            d_2=(num/1000)%10;
            d=d_1*10+d_2;
            if(m==d){
                l=(num*10000)+date(num);
                if(l>(num*10000)&&l!=n)break;
            }
            num++;
        }

        System.out.println(x);
        System.out.println(l);
    }//20200202
    static int date(int num){
        int m,d,m_1,m_2,d_1,d_2;
        m_1=num%10;
        m_2=(num/10)%10;
        m=m_1*10+m_2;
        d_1=(num/100)%10;
        d_2=(num/1000)%10;
        d=d_1*10+d_2;
        if(m>12||m<=0||d<=0||d>31)return 0;
        if(m==1||m==3||m==5||m==7||m==8||m==10||m==12&&d<=31){
            return m*100+d;
        }
        if(m==4||m==6||m==9||m==11&&d<=30){
            return m*100+d;
        }
        if(num%4==0&&num%100!=0){
           if(m==2&&d<=29)return m*100+d;
        }
        if(m==2&&d<=28)return m*100+d;
        return 0;
    }
}
